package cn.rui.config;

import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;

/**
 * @author 徽州大都督
 * @date 2020/8/16
 */
@Configuration
public class ImgConfig {

    /**
     * 配置上传文件大小的配置
     *
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //  单个数据大小
        factory.setMaxFileSize(DataSize.parse ("10240KB")); //5MB
        /// 总上传数据大小
        factory.setMaxRequestSize(DataSize.parse ("102400KB"));
        return factory.createMultipartConfig();
    }
}
